﻿using System.Linq;

public class ButtonModel : IButtonAction {
	public ButtonModel(UIListView model, UIListView element, ElementType type) {
		_model = model;
		_element = element;
		_type = type;
	}

	public void DisabledElement() {
		_element.SetEnabled(false);
	}

	public void Action() {
		foreach (var uiListItem in _model.GetItems().Where(uiListItem => uiListItem.IsButtonModel())) {
			uiListItem.GetButtonModel().DisabledElement();
		}
		_element.SetEnabled(true);
		MapEditorBaseData.GetInstance.SetModelType(_type);
		var firstItem = _element.GetItems().First();
		if (firstItem.IsButtonElement()) {
			firstItem.GetButtonElement().Action();
		}
	}

	// === Private ====================================================================================================
	private readonly UIListView _model;
	private readonly UIListView _element;
	private readonly ElementType _type;
}
